home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Workbench Add-On
/
Workbench Add-On - Volume 1.iso
/
BBS-Archive
/
Comm
/
AmiTCP30b2.lha
/
src
/
appl
/
napsaterm
/
napsaterm.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-05-18
|
6KB
|
253 lines
RCS_ID_C="$Id: napsaterm.c,v 3.8 1994/05/18 00:20:08 ppessi Exp $";
/*
* napsaterm.c --- NapsaTerm terminal emulator
*
* Author: ppessi <Pekka.Pessi@hut.fi>
*
* Copyright (c) 1993 Pekka Pessi
*
* Created : Mon Oct 18 17:23:37 1993 ppessi
* Last modified: Tue May 17 03:15:11 1994 ppessi
*
* Copyright 1988, 1989 Chris Newman
* All Rights Reserved
* Permission is granted to copy, modify, and use this as long
* as this notice remains intact. This is a nifty program.
*
* Parts of this program were swiped from Joe Keane's jterm, other parts
* were swiped from ITC's h19 terminal, and still others from gnu-emacs eterm.
*
* DISCLAIMER: the author (and maintainer) of this program is not responsible
* for any damage or other problems caused by it.
*
* $Log: napsaterm.c,v $
* Revision 3.8 1994/05/18 00:20:08 ppessi
* *** empty log message ***
*
* Revision 3.7 1994/05/14 14:10:48 ppessi
* Removed separate tektronix version
*
* Revision 3.6 1994/05/14 10:58:42 ppessi
* Updated for telnet code. Moved revision file include here from
* global include file "nifty.h".
*
* Revision 3.4 1994/05/12 10:53:05 ppessi
* Merged changes from Napsaterm 3.5 by R. Knop
*
*/
#include <stdlib.h>
#include "nifty.h"
#include "amiga.h"
#include "display.h"
#include "nio.h"
#include "napsaprefs.h"
#include <string.h>
#include <stdarg.h>
#include <signal.h>
#include "napsaterm_rev.h"
const char ProgName[] = VERS;
const char version[] = VERSTAG;
const char copyright[] =
"Napsaterm, terminal emulator for AmiTCP/IP, Internation version 3\n"
"Copyright © 1991, 1993 Pekka Pessi and AmiTCP/IP Group, "
"<amitcp-group@hut.fi>,\n"
"Helsinki University of Technology, Finland.\n"
"For full copyright information see supporting documentation.\n"
"Original NiftyTerm © Copyright 1990 by Chris Newman and Todd Williamson.\n"
"All Rights Reserved.\n"
"This is a nifty program.\n";
/* Non-standard libraries */
struct GfxBase *GfxBase = NULL;
struct IntuitionBase *IntuitionBase = NULL;
struct DiskfontBase *DiskfontBase = NULL;
struct Library *IconBase = NULL;
struct Library *TimerBase = NULL;
struct MsgPort *timeport = NULL;
struct timerequest *timereq = NULL;
BPTR logfile = NULL; /* current log file */
BOOLEAN started_from_workbench = FALSE;
char MEMORY_ERROR_MSG[] = "Out of memory";
/* This allows terminal answerback messages
*/
int write_to_tty(char *buf, int count)
{
if (iotype != stdio)
return (nwrite(buf, count));
dsputs(buf);
return (count);
}
void amigainit(void)
{
GfxBase = (struct GfxBase *)
OpenLibrary("graphics.library", 37L);
IntuitionBase = (struct IntuitionBase *)
OpenLibrary("intuition.library", 37L);
DiskfontBase = (struct DiskfontBase *)
OpenLibrary("diskfont.library", 37L);
IconBase = OpenLibrary("icon.library", 37L);
timeport = CreateMsgPort();
if (timeport) {
timereq = (void *)CreateIORequest(timeport, sizeof(*timereq));
}
if (!GfxBase || !IntuitionBase || !DiskfontBase || !IconBase
|| !timeport || !timereq) {
fatalError("Problem during initialization.\n"
"A needed library or resource was not found.\n");
}
if (OpenDevice(TIMERNAME, UNIT_VBLANK, (struct IORequest *)timereq, 0)) {
fatalError("Problem opening " TIMERNAME);
}
TimerBase = (struct Library *)timereq->tr_node.io_Device;
timereq->tr_node.io_Message.mn_Node.ln_Type = NT_REPLYMSG;
}
void amigaquit(void)
{
#ifdef TEKTRONICS /*Added RKNOP 940328*/
closetekwin();
#endif
if (timereq) {
if (TimerBase) {
if (!CheckIO(timereq)) {
AbortIO(timereq);
WaitIO(timereq);
}
CloseDevice((struct IORequest *)timereq), TimerBase = NULL;
}
DeleteIORequest((struct IORequest *)timereq), timereq = NULL;
}
if (timeport)
DeleteMsgPort(timeport), timeport = NULL;
nclose();
if (IconBase)
CloseLibrary(IconBase), IconBase = NULL;
if (GfxBase)
CloseLibrary((struct Library*)GfxBase), GfxBase = NULL;
if (IntuitionBase)
CloseLibrary((struct Library*)IntuitionBase), IntuitionBase = NULL;
if (DiskfontBase)
CloseLibrary((struct Library*)DiskfontBase), DiskfontBase = NULL;
if (logfile)
Close(logfile), logfile = NULL;
}
static void iopoll(void)
{
int n;
if ((n = nnread(iobuf, sizeof(iobuf))) > 0) {
if (logfile != (BPTR) NULL && n && (Write(logfile, iobuf, n) != n)) {
Close(logfile);
logfile = (BPTR) NULL;
PutStr("Error writing to log file\n");
}
termout(iobuf, n);
} else if (n < 0) {
/* IO error? EOF? let's quit */
if (np.wait_to_end) {
waitToEnd();
}
dsquit();
amigaquit();
exit(0);
}
}
/*
* niftyterm entry point
*/
int main(int argc, char **argv)
{
long winmask, timemask, mask, iomask;
/* Disable ^C signaling */
signal(SIGINT, SIG_IGN);
started_from_workbench = argc == 0;
amigainit();
if (started_from_workbench) {
argv = parsewbargs((struct WBStartup *)argv);
} else {
argv = parseargs(argv);
}
if (np.stdio) {
iotype = stdio;
if (np.show_version) {
PutStr(version);
PutStr(copyright);
}
} else {
/*
* Set IO type depending of the device name
*/
if (np.device) {
if (!stricmp(np.device, "dnet")) {
iotype = dnet;
} else if (!stricmp(np.device, "net")) {
iotype = rlogin;
} else if (!stricmp(np.device, "telnet")) {
iotype = telnet;
} else {
iotype = serial;
}
}
}
/* Use ANSI linefeed mode */
np.ansi_LNM = iotype == serial;
ninit(iotype);
if (np.logname)
logfile = Open(np.logname, MODE_NEWFILE);
dsinit();
iomask = nopen(argv);
winmask = dsmask();
timemask = dsflashinit();
for (;;) {
#ifdef TEKTRONICS /*added RKNOP 940328*/
mask = Wait(iomask | winmask | tekwinmask | timemask);
#else
mask = Wait(iomask | winmask | timemask);
#endif
if (mask & timemask) {
dscheckflash();
}
if (mask & winmask) {
dspoll();
}
#ifdef TEKTRONICS /*added RKNOP 940121*/
if (mask & tekwinmask) {
tekpoll();
}
#endif
if (mask & iomask) {
iopoll();
}
}
/*NOTREACHED*/
}